// ex1
function generatePromise() {
  return new Promise((resolve, reject) => {
    console.log('promise start');
    resolve('promise resolve');
    console.log('promise resolved');
  });
}
function main() {
  generatePromise().then(() => {
    console.log('then');
  });
  console.log('main end');
}

main();

// promise start
// promise resolved
// main end
// then

// ex2
function generatePromise() {
  return new Promise((resolve, reject) => {
    console.log('promise start');
    setTimeout(() => {
      console.log('settime 2');
      resolve('promise resolved');
    }, 0);
    console.log('promise resolved');
  });
}
function main() {
  setTimeout(() => {
    console.log('settime 1');
  }, 0);
  generatePromise().then(data => {
    console.log(data + ' then');
  });
  console.log('main end');
}

main();

// promise start
// promise resolved
// main end
// undefined
// settime 1
// settime 2
// promise resolvedthen
